package com.shujia.wyh.day24;


import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class FileReaderDemo1 {
    public static void main(String[] args) throws IOException {
//        InputStreamReader isr = new InputStreamReader(new FileInputStream("a.txt"));
        //简化写法创建字符输入流对象
        FileReader fr = new FileReader("a.txt");
        //一次读取一个字符
//        int ch = 0;
//        while ((ch = fr.read()) != -1) {
//            System.out.print((char) ch);
//        }
        System.out.println("========================");
        //一次读取一个字符数组
        char[] chars = new char[1024];
        int length = 0;
        while ((length = fr.read(chars)) != -1) {
            String s = new String(chars, 0, length);
            System.out.println(s);
        }

        //释放资源
        fr.close();

    }
}
